package com.wise.wing.activity.settting;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.VolleyError;
import com.bm.corelibs.logic.BaseLogic.NListener;
import com.bm.corelibs.utils.SharedPreferencesUtil;
import com.bm.corelibs.utils.ToastMgr;
import com.wise.wing.R;
import com.wise.wing.activity.logic.SettingManager;
import com.wise.wing.activity.main.BaseActivity;
import com.wise.wing.bean.BaseData;
import com.wise.wing.constant.Constant;
import com.wise.wing.views.CommonNavigationBar;


public class FeedbackActivity extends BaseActivity {
	EditText feedback_text;
	Button feedback_btn;
	CommonNavigationBar bar;
	SettingManager manager = new SettingManager();
	SharedPreferencesUtil preferencesUtil;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback);
		findViews();
		init();
		addListeners();
	}

	@Override
	public void findViews() {
		bar = (CommonNavigationBar) findViewById(R.id.navi);
		bar.setListener(null);
		bar.setTitle("意见反馈");
		feedback_text = (EditText) findViewById(R.id.feedback_text);
		feedback_btn = (Button) findViewById(R.id.feedback_btn);
	}

	@Override
public void init() {
	preferencesUtil = new SharedPreferencesUtil(mActivity, Constant.SpName);
}
	
	
	

	@Override
	public void addListeners() {
		feedback_btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (feedback_text.getText().toString().trim().length() < 10
						|| feedback_text.getText().toString().trim().length() > 250) {
					showToast("请输入10-250个字");
				} else {
					loadingDialog.show();
					manager.advise(feedback_text.getText().toString(),preferencesUtil.getStringByKey("id"),
							getCancelListener());
				}
			}
		});
	}

	private NListener<BaseData> getCancelListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					finish();
					showToast("非常感谢您的反馈");
				} else {
					ToastMgr.show(data.msg);
				
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

}
